package com.dycc.main_componet.view.impl;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.dycc.libary.base.StackActivity;
import com.dycc.libary.view.NoScrollViewPager;
import com.dycc.main_componet.R;
import com.dycc.main_componet.R2;
import com.dycc.normal_tab_fcompont.BadgeDismissListener;
import com.dycc.normal_tab_fcompont.JPTabBar;
import com.dycc.normal_tab_fcompont.OnTabSelectListener;

import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = "/main_componet/activity/MainActivity",name = "主页")
public class MainActivity extends StackActivity implements BadgeDismissListener, OnTabSelectListener {

    @BindView(R2.id.main_mainpager_viewpager)
    NoScrollViewPager mainViewPager;
    @BindView(R2.id.tabbar)
    JPTabBar mainTabBar;

    FragmentPagerAdapter adapter;

    private String[] titlesName;
    private int[] titleNormalIcons;
    private int[] titleSelectedIcons;
    private Fragment[] fragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //这是一个修改
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT); //也可以设置成灰色透明的，比较符合Material Design的风格
        }
        ButterKnife.bind(this);
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();

    }

    @Override
    protected void initView() {
        mainTabBar.setContainer(mainViewPager);
        mainViewPager.setNoScroll(false);
    }





    @Override
    protected void initData() {
        titleNormalIcons = new int[]{R.drawable.main_c_mainfragment_tab_index_normal_icon,
                R.drawable.main_c_mainfragment_tab_find_normal_icon, R.drawable.main_c_mainfragment_tab_message_normal_icon, R.drawable.main_c_mainfragment_tab_mine_normal_icon};
        titleSelectedIcons = new int[]{R.drawable.main_c_mainfragment_tab_index_select_icon,
                R.drawable.main_c_mainfragment_tab_find_select_icon, R.drawable.main_c_mainfragment_tab_message_select_icon, R.drawable.main_c_mainfragment_tab_mine_select_icon};
        titlesName = new String[]{"主页", "发现", "消息", "个人"};
        fragments = new Fragment[]{
                (Fragment) ARouter.getInstance().build("/main_componet/fragment/Main_CIndexFragment").navigation(),
                (Fragment) ARouter.getInstance().build("/main_c/fragment/Main_CDiscoveryFragment").navigation(),
                (Fragment) ARouter.getInstance().build("/main_c/fragment/Main_CMineFragment").navigation()
        };

        mainTabBar.setTitles(titlesName)
                .setNormalIcons(titleNormalIcons)
                .setSelectedIcons(titleSelectedIcons)
                .generate();
        mainTabBar.setSelectedColor(Color.parseColor("#0F92FE"));

        adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return (fragments != null) ? fragments.length : 0;
            }
        };
        mainViewPager.setAdapter(adapter);
        mainViewPager.setOffscreenPageLimit(4);
        mainTabBar.setDismissListener(this);
        //设置Badge消失的代理
        mainTabBar.setTabListener(this);
        mainTabBar.setUseScrollAnimate(true);
//        mainTabBar.getMiddleView().setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                Toast.makeText(MainActivity.this,"中间点击",Toast.LENGTH_SHORT).show();
//                ARouter.getInstance().build("/main_componet/activity/LoginActivity")
//                        .withSerializable(BaseInterceptor.BIND_KEY, new InterceptorBind()
////                                        .addInterceptor(new InterceptorBind.Bind(LoginInterceptor.class))
////                                .addInterceptor(new InterceptorBind.Bind(TestInterceptor.class, false))
//                        )
//                        .navigation();
//            }
//        });
    }

    @Override
    public void onDismiss(int position) {

    }

    @Override
    public void onTabSelect(int index) {

    }
}
